package com.njlime.member.service.app;

import com.njlime.core.helper.PageBean;
import com.njlime.member.entiies.MemberFocus;
import com.njlime.member.repository.app.AppMemberFocusDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by Dean on 2017/10/9.
 */
@Service
public class AppMemberFocusService {
    @Resource
    private AppMemberFocusDao appMemberFocusDao;
    /**
     * 记录添加
     */
    @Transactional(readOnly = false)
    public void save(MemberFocus memberFocus){
        memberFocus.setCreate_time(new Date());
        appMemberFocusDao.save(memberFocus);
    }

    /**
     * 列表
     */
    public PageBean getByMemberId(PageBean pageBean,int memberId){
        return appMemberFocusDao.getByMemberId(pageBean, memberId);
    }

    /**
     * 删除
     * @param unit_id
     * @param user_id
     */
    @Transactional
    public void del(int unit_id, int user_id){
        appMemberFocusDao.del(unit_id, user_id);
    }

    /**
     * 是否已被关注
     * @param unit_id
     * @param user_id
     * @return
     */
    public int isFocus(int unit_id, int user_id){
        int num = appMemberFocusDao.isFocus(unit_id, user_id);
        return num > 0 ? 1 : 0;
    }

    public int focusNum(int unit_id){
        return appMemberFocusDao.focusNum(unit_id);
    }

}
